package com.dm.commons.result;

/*
* 返回工具类：定义几个返回固定格式
*
* */
public class ResultUtil {

    /*
    * 返回自定义code和data数据
    * */
    public static <T> Result<T> defineSuccess(Integer code, T data ,String message){
        Result<T> result = new Result<>();
        return result.setCode(code).setMessage(message).setData(data);
    }

    /*
    * 返回枚举中定义的code和data数据
    * */
    public static <T> Result<T> success(T data){
        Result<T> result = new Result<>();
        return result.setCode(ResultEnum.SUCCESS.code).setMessage(ResultEnum.SUCCESS.message).setData(data);
    }

    /*
     * 返回枚举中定义的code和message信息
     * */
    public static <T> Result<T> success(String message){
        Result<T> result = new Result<>();
        return result.setCode(ResultEnum.SUCCESS.code).setMessage(message);
    }

    /*
    * 只返回枚举中定义的code不返回数据
    * */
    public static <T> Result<T> success(){
        Result<T> result = new Result<>();
        return result.setCode(ResultEnum.SUCCESS.code).setMessage(ResultEnum.SUCCESS.message);
    }



    /*
    * 失败不返回数据，返回自定义code和message信息
    * */
    public static <T> Result<T> defineFail(Integer code,String message){
        Result<T> result = new Result<>();
        return result.setCode(code).setMessage(message);
    }

    /*
    * 返回枚举中定义的code和message信息
    * */
    public static <T> Result<T> fail(String message){
        Result<T> result = new Result<>();
        return  result.setCode(ResultEnum.FAIL.code).setMessage(message);
    }

    /*
     * 返回枚举中定义的code和message信息
     * */
    public static <T> Result<T> fail(String message ,String errorMessage){
        Result<T> result = new Result<>();
        return  result.setCode(ResultEnum.FAIL.code).setMessage(message).setErrorMessage(errorMessage);
    }

    /*
    * 返回自定义code、message信息和data数据
    * */
    public static <T> Result<T> define(Integer code, String message, T data) {
        Result<T> result = new Result<>();
        return result.setCode(code).setMessage(message).setData(data);
    }




}